/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.mb;

import br.siagefi.model.FornecedorPJ;
import br.siagefi.service.FornecedorPJService;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Paulo Lavarini
 */
@SessionScoped
@ManagedBean
public class FornecedorPJBean implements Serializable{
    
    private FornecedorPJ fornecedorPJ;
    private final FornecedorPJService service;
    private List<FornecedorPJ> fornecedoresPJ;

    public FornecedorPJBean() {
        this.fornecedorPJ = new FornecedorPJ();
        this.service = new FornecedorPJService();
        this.carregarLista();
    }
    
     public final void carregarLista(){
         this.fornecedoresPJ = service.listar();
    }
    
    public String gravar(){
        service.inserir(this.getFornecedorPJ());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "fornecedorPJ?faces-redirect=true";
    }
    
    public String alterar(FornecedorPJ fornecedorPJ){
        this.setFornecedorPJ(fornecedorPJ);
        return "incluirFornecedorPJ";
    }
    
     public String remover(){
        service.remover(this.getFornecedorPJ());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "fornecedorPJ";
    }
     
    public String remover(FornecedorPJ fornecedorPJ){
        service.remover(fornecedorPJ);
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "fornecedorPJ";
    }
  
    public void limparFormularioDoJsf(){
        this.fornecedorPJ = new FornecedorPJ();
    }

    public FornecedorPJ getFornecedorPJ() {
        return fornecedorPJ;
    }

    public void setFornecedorPJ(FornecedorPJ fornecedorPJ) {
        this.fornecedorPJ = fornecedorPJ;
    }

    public List<FornecedorPJ> getFornecedoresPJ() {
        return fornecedoresPJ;
    }

    public void setFornecedorPJs(List<FornecedorPJ> fornecedoresPJ) {
        this.fornecedoresPJ = fornecedoresPJ;
    }
}
